package com.huawei.appgallery.packagemanager.impl.install.process;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.packagemanager.impl.base.PackageBaseActivity;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.cnu;
import o.cop;
import o.cov;
import o.cpn;
import o.cpp;
import o.cps;
import o.cpt;

public class PackageInstallerActivity extends PackageBaseActivity {
    private String ʼ = "";
    private boolean ʽ;
    private long ˋ;
    private String ˎ = "";
    private String ˏ = "";
    private boolean ॱ = false;

    public void onCreate(Bundle bundle) {
        Intent ˎ;
        super.onCreate(bundle);
        SafeIntent safeIntent = new SafeIntent(getIntent());
        this.ˎ = safeIntent.getStringExtra(com.huawei.fastengine.fastview.download.install.PackageInstallerActivity.INSTALL_PATH);
        this.ˏ = safeIntent.getStringExtra(com.huawei.fastengine.fastview.download.install.PackageInstallerActivity.INSTALL_PACKAGENAME);
        this.ॱ = safeIntent.getBooleanExtra(com.huawei.fastengine.fastview.download.install.PackageInstallerActivity.INSTALL_EXISTING, false);
        this.ˋ = safeIntent.getLongExtra("install_taskId", 0);
        if (this.ॱ) {
            if (TextUtils.isEmpty(this.ˏ)) {
                finish();
                cnu.ˏ.ˊ("PackageInstallerActivity", "can not find packageName.");
                return;
            }
            cov.ˏ(getApplicationContext()).removeMessages(("hwInstallExisting:" + this.ˏ).hashCode());
            ˎ = cps.ˎ((Context) this, this.ˏ);
            this.ʼ = "installExisting:" + this.ˏ;
        } else if (TextUtils.isEmpty(this.ˎ)) {
            finish();
            cnu.ˏ.ˊ("PackageInstallerActivity", "can not find filePath.");
            return;
        } else {
            cov.ˏ(getApplicationContext()).removeMessages(this.ˎ.hashCode());
            this.ʽ = safeIntent.getBooleanExtra("install_change_backup_path", false);
            if (VERSION.SDK_INT >= 24) {
                ˎ = cpt.ˎ((Context) this, this.ˎ);
            } else {
                ˎ = cps.ॱ((Context) this, this.ˎ);
            }
            this.ʼ = this.ˎ;
        }
        if (ˎ == null) {
            cnu.ˏ.ˊ("PackageInstallerActivity", "error installIntent");
            finish();
            return;
        }
        ˎ.putExtra("android.intent.extra.NOT_UNKNOWN_SOURCE", true);
        ˎ.putExtra("android.intent.extra.RETURN_RESULT", true);
        cnu.ˏ.ˋ("PackageInstallerActivity", "onCreate filePath:" + this.ˎ + ",packageName:" + this.ˏ + ",taskId:" + getTaskId());
        try {
            startActivityForResult(ˎ, 100);
            if (cop.ˎ != null) {
                cop.ˎ.ˎ(this.ʼ, this);
            }
        } catch (ActivityNotFoundException e) {
            cnu.ˏ.ˊ("PackageInstallerActivity", "can not start install action");
            cpp.ˏ(getApplicationContext(), this.ˏ, -1000001, this.ˋ, 5, false);
            finish();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        int i3 = -10004;
        super.onActivityResult(i, i2, intent);
        if (100 == i) {
            this.ˊ = true;
            if (i2 == 0) {
                ˊ();
            } else {
                if (intent != null) {
                    i3 = intent.getIntExtra("android.intent.extra.INSTALL_RESULT", -10004);
                }
                if (i3 == -115) {
                    ˊ();
                    finish();
                    return;
                }
                if (i3 >= 0 && VERSION.SDK_INT == 24) {
                    i3++;
                }
                if (VERSION.SDK_INT >= 24 || this.ॱ || (!(-3 == i3 || -2 == i3) || this.ʽ)) {
                    cnu.ˏ.ˋ("PackageInstallerActivity", "package install system callback:packageName:" + this.ˏ + ",returnCode:" + i3);
                    cpp.ˏ(getApplicationContext(), this.ˏ, i3, this.ˋ, 4, false);
                } else {
                    cnu.ˏ.ˋ("PackageInstallerActivity", "package install system callback:packageName:" + this.ˏ + ",returnCode:" + i3 + ",can changePath:true");
                    new cpn().show(getFragmentManager(), "ChangePathDialog");
                    return;
                }
            }
        }
        finish();
    }

    public void ˊ(boolean z) {
        String str;
        if (z) {
            str = "user agree change path to install again";
        } else {
            str = "user do not agree change path to install again";
        }
        cnu.ˏ.ˋ("PackageInstallerActivity", str);
        finish();
        cpp.ˏ(getApplicationContext(), this.ˏ, -3, this.ˋ, 4, z);
    }

    public void ˊ() {
        super.ˊ();
        cnu.ˏ.ˋ("PackageInstallerActivity", "package install system callback:packageName:" + this.ˏ + " user cancel!");
        cpp.ˏ(getApplicationContext(), this.ˏ, -1000001, this.ˋ, 4, false);
    }

    public void onDestroy() {
        super.onDestroy();
        finishActivity(100);
        if (cop.ˎ != null) {
            cop.ˎ.ˏ(this.ʼ, this);
        }
        cnu.ˏ.ˋ("PackageInstallerActivity", "onDestroy removeTaskId:" + this.ˎ);
    }
}
